<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />

    <FilterTable ref="table" :height="'auto'" :columns="columns" :dataSource="tableList" :onColumnsChange="columns => (this.columns = columns)" :isSelectColumn="false"></FilterTable>
    <div style="height: 47px"></div>
    <FormPanel ref="formPanel" :list="formList1" :cols="1" :formType="'add'" :isSubmitBtn="false" @formChange="changeHandle" />
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button size="small" type="primary" :click="dataHandle.bind(this, 60621003)">同 意</multiuse-button>
      <multiuse-button size="small" type="primary" :click="dataHandle.bind(this, 60621005)">驳 回</multiuse-button>
      <el-button @click="closeDrawer(1)">返回</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryDailyByDate, submitByStatus } from '@/api/omSale/DealerDaily/DealerQaudit';

export default {
  name: 'addModel',
  mixins: [dictionary],

  props: ['rowData'], // 上个页面带入的值
  data() {
    this.saveData = null;
    this.BaseTable = null;
    return {
      formList: this.createdFrom(),
      columns: this.createdTable(),
      tableList: [],
      fromData: {},
      formList1: this.formListform()
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.init();
  },
  methods: {
    async init() {
      const res = await queryDailyByDate({ applyDate: this.rowData.applyDate, ownerCode: this.rowData.ownerCode });
      if (res.resultCode == 200) {
        this.formList.map(x => {
          if (x.fieldName == 'applyDate') {
            x.initialValue = res.data.ttVsDailyDTOs ? res.data.ttVsDailyDTOs[0].applyDate : '';
          } else {
            x.initialValue = res.data[x.fieldName];
          }
        });

        this.tableList = res.data.modelCacheVOList ? JSON.parse(JSON.stringify(res.data.modelCacheVOList)) : res.data.ttVsDailyDTOs || [];
      }
    },
    // 同意 驳回
    async dataHandle(status) {
      this.formList1[0].rules[0].required = status == 60621005 ? true : false;
      this.$refs.formPanel.SUBMIT_FORM();
      this.saveData.ttVsDailyDTOs = this.tableList;
      this.saveData.dailyStatus = status; // 状态

      const res = await submitByStatus(this.saveData);
      if (res.resultCode == 200) {
        this.$notify.success({ title: '提示信息', message: '操作成功' });
        this.$emit('close', false, 'refresh');
      }
    },
    closeDrawer() {
      this.$emit('close', false);
    },
    changeHandle(val) {
      this.saveData = val;
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'ownerCode',
          placeholder: '请输入',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请选择',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '事业部',
          fieldName: 'deptName',
          placeholder: '请输入',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '办事处',
          fieldName: 'officeName',
          placeholder: '请输入',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '区域经理',
          fieldName: 'regionalManager',
          placeholder: '请输入区域经理',
          disabled: true
        },
        {
          type: 'DATE',
          label: '上报日期',
          fieldName: 'applyDate',
          dateType: 'exactdate',
          disabled: true
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '车型',
          dataIndex: 'modelName'
        },
        {
          title: '展厅访问',
          dataIndex: 'exhibitionHallVisit'
        },
        {
          title: '来电/网络',
          dataIndex: 'callOrNetwork'
        },
        {
          title: '外拓',
          dataIndex: 'promoting'
        },
        {
          title: '留档',
          dataIndex: 'maintained'
        },
        {
          title: '试驾',
          dataIndex: 'testDrive'
        },
        {
          title: '新增订单',
          dataIndex: 'newOrder'
        },
        {
          title: '累计未交',
          dataIndex: 'accumulatedUnpaid'
        },
        {
          title: '开票',
          dataIndex: 'billCount'
        }
      ];
    },
    formListform() {
      return [
        {
          type: 'TEXT_AREA',
          label: '审核备注',
          fieldName: 'checkRemark',
          placeholder: '请输入',
          initialValue: '',
          rules: [{ required: false, message: '请输入', trigger: 'blur' }]
        }
      ];
    }
  }
};
</script>
